package com.ciwong.mobilelib.utils;

import android.util.SparseArray;
import android.view.View;

/**
 * View控件缓存类
 *
 * @author Administrator
 * @version ciwong v.1.0 2015/4/30 17:23
 * @since ciwong v.1.0
 */
public class ViewHolder
{
    public static <T extends View> T get(View view, int id)
    {
        SparseArray<View> holder = (SparseArray<View>) view.getTag();
        if (holder == null)
        {
            holder = new SparseArray<View>();
            view.setTag(holder);
        }
        View childView = holder.get(id);
        if (childView == null)
        {
            childView = view.findViewById(id);
            holder.put(id, childView);
        }
        return (T) childView;
    }

}
